<template>
  <div>
    <div>
      <button type="button" style="width:50px;height:20px;background:cyan" @click="Import">导出!</button>
    </div>
  </div>
</template>

<script>
export default {
  data () {
    return {
      
    }
  },
  methods: {
    Import(){
      //导出
      this.$http({
        url: "/api/files/exportExcel", // 接口名字
        method: "get",
        headers: {
          'Authorization': localStorage.getItem('token'),
        },
        params: {
          type: "softDistrict"
        },
        responseType: "blob"
      }).then(res => {
          if (res.data.type == "application/msexcel") {
             console.log("导出成功请查看");
            
            // return;
            this.download(res);
          } else {
             console.log("导出错误");
          }
        })
        .catch(error => console.log({ error }));
    },
    download(data) {
      if (!data) {
        return;
      }
      console.log(data);
      console.log([data.data]);
      var blob = new Blob([data.data], {
        type: "application/vnd.ms-excel;charset=utf-8"
      });
      console.log(blob);
      var url = window.URL.createObjectURL(blob);
      var aLink = document.createElement("a");
      aLink.style.display = "none";
      aLink.download = "设备评估信息.xlsx";
      aLink.href = url;
      document.body.appendChild(aLink);
      aLink.click();
    }
  },
}
</script>

<style>

</style>